﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;

namespace KitBuilder.DataAccess
{
    class StockNHibernateDAO : GenericNHibernateDAO<Stock>,StockDAO
    {
        private ISession session = null;

        public StockNHibernateDAO()
        {
        }

        public override Stock FindByID(long id)
        {
            Stock foundStockItem = new Stock();
            return foundStockItem;
        }

        public override List<Stock> FindAll()
        {
            List<Stock> allStockItems = null;
            if (session != null)
            {
                session = GenericNHibernateDAO<Stock>.OpenSession();
            }

            return allStockItems;
        }

        public override void MakePersistent(Stock entry)
        {
            session = OpenSession();
            using (ITransaction transaction = session.BeginTransaction())
            {
                if (session != null)
                {
                    session.SaveOrUpdate(entry);
                }
                transaction.Commit();
            }
            CloseSession();
        }

        public override void MakeTransient(Stock entry)
        {
        }

        public override void Delete(Stock entry)
        {
            using (ITransaction transaction = session.BeginTransaction())
            {
                if (session != null)
                {
                    session.Delete(entry);
                }
                transaction.Commit();
            }
        }


        public Stock FindByPCode(string productCode)
        {
            return new Stock();
        }
    }
}
